package test2;

public class MyRunnable implements Runnable{
    int num = 0;
    @Override
    public void run() {
        while (true){

                if (method()) break;

        }



    }

    private synchronized boolean method() {
        if (num < 100){
            System.out.println(Thread.currentThread().getName() + String.format("卖第"+num+"张票"));
            num ++;
        }else{
            return true;
        }
        return false;
    }
}
